
#ifndef PAINTOPERATION_H
#define PAINTOPERATION_H

#include <BSet>
#include <BCircle>
#include <BIcon>
#include <BImage>
#include <BPicker>
#include <BHandler>
#include <BSurface>
#include <BNode>
#include <BButton>
#include <BSlider>
#include <BSpinBox>
#include <BDialog>
#include <BButtonGroup>
#include <BProgressBar>
#include <BTreeWidget>
#include <BSpacer>
#include <BCheckBox>
#include <BGridLayout>
#include <BHBoxLayout>
#include <BVBoxLayout>

#include "Operation.h"

class PaintOperation : public Operation
{
public:
	PaintOperation();
	~PaintOperation();

protected:
	void initUI();
	bool intersectTest(const BQuad& quad, const BTriangle& trig);
	void catchPixels(const BQuad& quad);
	void paintPixels(const BQuad& quad);

protected:
	void slotAssetChanged(BObject* object, const BValue& value);
	void slotImageButtonClicked(BObject* object, const BValue& value);
	void slotImageButtonRightClicked(BObject* object, const BValue& value);
	void slotBrushSizeChanged(BObject* object, const BValue& value);
	void slotColorButtonClicked(BObject* object, const BValue& value);

protected:
	virtual void attached(BWidget* widget);
	virtual void detached(BWidget* widget);

	virtual void paint(BPainter& painter);
	virtual void update(double time);

	virtual void freshEvent(const BEvent& event);

	virtual bool keyDownEvent(const BKeyEvent& keyEvent);
	virtual bool keyUpEvent(const BKeyEvent& keyEvent);

	virtual bool mousePressEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseReleaseEvent(const BMouseEvent& mouseEvent);
	virtual bool mouseMoveEvent(const BMouseEvent& mouseEvent);

	virtual bool mouseClickEvent(const BMouseEvent& mouseEvent);

private:
	BHolder<BHBoxLayout>	_layout;
	BButton*				_imageButton;
	BSlider*				_brushSizeSlider;
	BSpinBox*				_brushSizeSpinBox;
	BButton*				_brushColorButton;

	BRect					_brushRect;
	bool					_pressed;
	bool					_shiftDown;
	bool					_ctrlDown;
	bool					_altDown;
	BArray<BPoint>			_pixelPoints;
};

#endif